package com.bocomm.tracevisualization.api.entity;

import lombok.Data;

/**
 * <p>
 * traceroute的每一行返回值
 * </p>
 *
 * @author cxp
 * @since 2024-03-20
 */
@Data
public class TraceTargetDataDetail {


    private Long id;

    /**
     * 源端ip
     */
    private String sourceIp;

    /**
     * 源端主机名
     */
    private String sourceHost;

    /**
     * 目标ip
     */
    private String targetIp;

    /**
     * 目标端主机名
     */
    private String targetHost;

    /**
     * 执行任务Id
     */
    private String jobId;

    /**
     * 数据采集时间
     */
    private Long traceTime;

    /**
     * 跃点id
     */
    private Integer hopId;

    /**
     * 监控所得时间
     */
    private Double traceResult;

    /**
     * 原始数据
     */
    private String originalData;

    /**
     * 是否成功达到目标ip
     */
    private boolean success;
    /**
     * 是否超时
     */
    private boolean timeOut;

    public TraceTargetDataDetail(TracerouteHop tracerouteHop) {
        this.targetIp = tracerouteHop.getLastTargetIp();
        this.hopId = tracerouteHop.getHopNumber();
        this.originalData = tracerouteHop.getSourceLine();
        this.success = tracerouteHop.isConnected();
        this.traceResult = tracerouteHop.getLastTrtTime();
    }
    public static TraceTargetDataDetail defaultSourceData( String sourceIP, String sourceHost){
        TraceTargetDataDetail traceTargetDataDetail = new TraceTargetDataDetail();
            traceTargetDataDetail.setSourceIp(sourceIP);
            traceTargetDataDetail.setTargetIp(sourceIP);
            traceTargetDataDetail.setTargetHost(sourceHost);
            traceTargetDataDetail.setSourceHost(sourceHost);
            traceTargetDataDetail.setSuccess(true);
            traceTargetDataDetail.setTimeOut(false);
            traceTargetDataDetail.setHopId(-1);

        return traceTargetDataDetail;
    }
    public TraceTargetDataDetail() {
    }
}
